﻿#include "cmdackframe.h"

using namespace IGBTProtocol;

CmdAckFrame::CmdAckFrame()
    : CmdFrame()
{
    _execCmdType = Cmd_Undef;
    _execCmdCount = 0;
    _execCmdRes = CmdExecRes_Undef;
    _errCode = 0;
}

bool CmdAckFrame::depack(QByteArray* buff)
{
    if(!CmdFrame::depack(buff))
        return false;

    unsigned short temp;
    temp = (unsigned char)(buff->at(13));
    temp <<= 8;
    temp += (unsigned char)(buff->at(12));

    if(temp == Cmd_SingleOpenCap
            || temp == Cmd_SingleCloseCap
            || temp == Cmd_TimerCap
            || temp == Cmd_FaultCap
            || temp == Cmd_StopCap)
        _execCmdType = (CmdType)temp;
    else return false;

    _execCmdCount = (unsigned char)(buff->at(14));

    temp = (unsigned char)(buff->at(15));
    if(temp == CmdExecRes_Cplt
            || temp == CmdExecRes_Failed
            || temp == CmdExecRes_Running)
        _execCmdRes = (CmdExecResType)temp;
    else return false;

    _errCode = (unsigned char)(buff->at(16));

    return true;
}
